﻿Public Class frmCierreCaja 

    Private Sub frmCierreCaja_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.vtotalpagosportipo' table. You can move, or remove it, as needed.
        Me.VtotalpagosportipoTableAdapter.Fill(Me.DbFireAndIceDataSet.vtotalpagosportipo)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.usuarios' table. You can move, or remove it, as needed.
        Me.UsuariosTableAdapter.Fill(Me.DbFireAndIceDataSet.usuarios)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.cierrecaja' table. You can move, or remove it, as needed.
        Me.CierrecajaTableAdapter.Fill(Me.DbFireAndIceDataSet.cierrecaja)
        FechaTextEdit.Text = FormatDateTime(FechaTextEdit.Text, DateFormat.ShortDate)

    End Sub

    Private Sub FechaTextEdit_EditValueChanged(sender As System.Object, e As System.EventArgs) Handles FechaTextEdit.EditValueChanged
        'Try
        VtotalpagosportipoTableAdapter.FillByFecha(DbFireAndIceDataSet.vtotalpagosportipo, FormatDateTime(FechaDateTimePicker.Text, DateFormat.ShortDate))
        'Catch ex As Exception
        '   MsgBox("No se pudo cargar")
        'End Try
    End Sub

    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            modificar.Enabled = True
            eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If

    End Sub

    Private Sub modificar_Click(sender As System.Object, e As System.EventArgs) Handles modificar.Click
        Mostrar()

    End Sub

    Private Sub guardar_Click(sender As System.Object, e As System.EventArgs) Handles guardar.Click
        If EfectivorealTextEdit.EditValue = 0 Then
            ErrorProvider1.SetError(EfectivorealTextEdit, "Debe ingresar el efectivo real en la caja")
        Else
            ErrorProvider1.SetError(EfectivorealTextEdit, Nothing)
            CierrecajaTableAdapter.UpdateQueryEfectivoReal(EfectivorealTextEdit.EditValue, Val(IdcierrecajaTextBox.Text))
            MessageBox.Show("Se guardó el efectivo real en caja exitosamente.")
            Mostrar()
        End If
    End Sub

    Private Sub IdcierrecajaTextBox_TextChanged(sender As System.Object, e As System.EventArgs) Handles IdcierrecajaTextBox.TextChanged
        ' TextEdit1.EditValue = VtotalpagosportipoTableAdapter.ScalarQueryTotalPorTipoPago(1, , FormatDateTime(FechaDateTimePicker.Text, DateFormat.ShortDate))
    End Sub
End Class